﻿var filesHtml = {};
var loanItems;
var url = new Url();
var $userId = url.GetQueryString("userId");
var $orderId = url.GetQueryString("orderId");
var serializer = new JSONSerializer();
var idCard;
//法定代表人
var legalperson;
var companyName;
var complayAddress;

var productTypeId = -1;

//银行流水实时信息
var BankRunning = 0;


var LoadRelationInfo = function () { };
LoadRelationInfo.prototype = {
    Url: "",
    Data: {},
    type: 0,
    CallBack: null,
    GetRelationInfo: function () {
        $this = this;
        this.Data.type = this.type;
        this.Data._ = Math.random();
        $.ajax({
            type: "post",
            dataType: "json",
            data: this.Data,
            url: this.Url,
            async: false,
            cache: false,
            complete: function () { },
            success: function (result) {
                if (result.Status) {
                    if ($this.CallBack) {
                        $this.CallBack(result.Data);
                    }
                }
                else {
                    alert(result.Message);
                }
            }
        });
    },
};



var loadinfo = new LoadRelationInfo();
loadinfo.Data = { OrderId: $orderId };


$(function () {

    //禁用特殊字符
    $('textarea:enabled').blur(function () {
        CheckSpecificKey($(this).val());
    });

    //页面元素隐藏与显示
    if ($("#displayMode").attr("data-total") === "True") {
        $(".tabs :last").css("display", "inline");
        $(".refuse").css("display", "inline");
        $(".passBasicInfo").css("display", "none");
        //跳转到批核信息页面进行批核
        $(".passTotal").css("display", "inline");
    }
    //只有初审才可以填写联系人信息，终审、综评不能修改
    //if ($("#displayMode").attr("data-disabled") === "True") {
    //    $(".opinion textarea").attr("disabled", "disabled");
    //    $(".btnInfoPreserve").css("display", "none");
    //}
    //综评、复议不显示“拒借”按钮
    if ($("#displayMode").attr("data-reconsider") === "True" || $("#displayMode").attr("data-total") === "True") {
        $(".refuseLoan").css("display", "none");
    }

    //复议不显示"退回"按钮
    if ($("#displayMode").attr("data-reconsider") === "True") {
        $(".tabs :last").css("display", "inline");
        $(".refuse").css("display", "inline");
        $(".passBasicInfo").css("display", "none");
        //跳转到批核信息页面进行批核
        $(".passTotal").css("display", "inline");
        $(".backBasicInfo").css("display", "none");
    }
    var $index = $('#displayMode').attr('data-index');
    for (var i = 0; i < $index; i++) {
        $(".verifyOpinion:eq('" + i + "')").css("display", "inline").find("textarea").attr("disabled", "disabled");
    }

    $(".verifyOpinion:eq('" + $index + "')").css("display", "inline");
    //加载数据
    $.ajax({
        url: "../Handler/LoanProductOrderHandler.ashx",
        type: "post",
        dataType: "json",
        data: { Type: 4, OrderId: $orderId, _: Math.random() },
        async: true,
        cache: false,
        success: function (result) {
            if (result.Status) {
                updateProgress(result.Data);
                loanItems = result.Data.LoanItems;
                if (result.Data.Verify) {
                    $("#workContactOpinion").val(result.Data.Verify.WorkContactOpinion);
                    $("#familyContactOpinion").val(result.Data.Verify.FamilyContactOpinion);
                    $("#emergContactOpinion").val(result.Data.Verify.EmergContactOpinion);
                    $.each(result.Data.Verify.result, function (index, item) {
                        $(".verifyOpinion:eq('" + item.Index + "')").find("textarea").val(item.AuditOpinion);
                    }); 
                }
                //加载文件信息
                $.each(result.Data.LoanItems, function (index, item) {
                    $("#FileTemplate").tmpl(item.Files).appendTo($("#fileContent"));
                    filesHtml["content" + item.AuthId] = $("#fileContent").html();
                    $("#fileContent").empty();
                });
                productTypeId = result.Data.Order.ProductTypeId;
                loadVerifyFiles(result.Data.Order.ProductTypeId);

                if (result.Data.Order) {
                    $userId = result.Data.Order.UserId;
                    serializer.DeSerializeToSpan($(".orderInfo"), result.Data.Order);

                    serializer.DeSerialize($("#orderData"), result.Data.Order);
                    if (result.Data.Order.IsAccordanceProduct) {
                        $("input[type='radio'][name=IsAccordanceProduct]:eq(0)").click();
                        var valueArr = result.Data.Order.ChangeProductName.split(',');
                        $(".ddlAccordanceProduct option[value='" + valueArr[1] + "']").prop("selected", true);
                    }
                    if (result.Data.Order.IsCoborrowLoan) {
                        $("input[type='radio'][name=IsCoborrowLoan]:eq(0)").click();
                        var coborrowName = result.Data.Order.CoborrowName;
                        var coborrowId = result.Data.Order.CoborrowDDL;
                        $(".ddlCoborrowLoan option[value='" + coborrowId + "']").prop("selected", true);
                        if (coborrowId == "-1") {
                            $("input.OtherCoborrowName").css("display", "block").val(coborrowName);
                        }
                    }
                    if (result.Data.Order.IsOpen) {
                        $("input[name='IsOpen']:eq(0)").attr("checked", true);
                    }
                    else {
                        $("input[name='IsOpen']:eq(0)").attr("checked", false);
                    }
                }
                else {
                    $("li:contains('批核信息')").css("display", "none");
                }
                serializer.DeSerializeToSpan($(".userInfo"), result.Data.User);
                idCard = result.Data.User.IDCard;
                showUserRepeatIDCard(result.Data.User.IDCard);
                showUserRepeatPhone(result.Data.User.Phone);
                showUserRepeatAddressPhone(result.Data.User.AddressTel);
                if (result.Data.Work == null) {
                    $("#span_WorkName").html("");
                    $("#span_WorkPhone").html("");
                    $("#span_CertifyTel").html("");
                    $("#span_CertifyTel2").html("");
                } else {
                    serializer.DeSerializeToSpan($(".workInfo"), result.Data.Work);
                    $("em[data-name='WorkEmail']").text(result.Data.Work.WorkEmail);
                    showUserRepeatWorkPhone(result.Data.Work.CompanyTel);
                    showUserRepeatCompanyName(result.Data.Work.CompanyName);
                    showUserRepeatCertifyTel(result.Data.Work.CertifyTel);
                    showUserRepeatCertifyTel2(result.Data.Work.CertifyTel2);
                }
                if (result.Data.Family == null) {
                    $("#span_LineaKinPhone").html("");
                    $("#span_OtherLinkManPhone").html("");
                    $("#span_EmergLinkManPhone1").html("");
                    $("#span_EmergLinkManPhone2").html("");
                } else {
                    serializer.DeSerializeToSpan($(".familyInfo"), result.Data.Family);
                    $("em[data-name='IsHaveChildValue']").text(result.Data.Family.IsHaveChildValue);
                    $("em[data-name='MaritalStatusValue']").text(result.Data.Family.MaritalStatusValue);
                    $("em[data-name='HousePropertyValue']").text(result.Data.Family.HousePropertyValue);
                    showUserRepeatOtherLinkManPhone(result.Data.Family.OtherLinkManPhone);
                    showUserRepeatLineaKinPhone(result.Data.Family.LineaKinPhone);
                    showUserRepeatEmergLinkManPhone1(result.Data.Family.EmergLinkManPhone1);
                    showUserRepeatEmergLinkManPhone2(result.Data.Family.EmergLinkManPhone2);
                }

                //手续信息：为预加载企业信息做准备
                legalperson = result.Data.User.Name;
                companyName = result.Data.Work.CompanyName;
                complayAddress = result.Data.Work.CompanyAddress;

            } else {
                alert(result.Message);
            }
        }
    });

    //综评批核
    $(".passTotal").click(function () {
        var $opinion = $(".verifyOpinion:eq('" + $index + "')").find("textarea").val().trim();
        if (!$opinion) {
            $(".verifyOpinion:eq('" + $index + "')").find("textarea").focus();
            return;
        }
        $("li:contains('批核信息')").click();
    });

    //拒件
    $(".refuse").click(function () {
        var $opinion = $(".verifyOpinion:eq('" + $index + "')").find("textarea").val().trim();
        if (!$opinion) {
            $(".verifyOpinion:eq('" + $index + "')").find("textarea").focus();
            return;
        }
        $.ajax({
            url: "../Handler/LoanProductOrderHandler.ashx",
            type: "post",
            dataType: "json",
            data: { AuditOpinion: $opinion, OrderId: $orderId, Type: 14, _: Math.random() },
            async: true,
            cache: false,
            complete: function () {
            },
            success: function (result) {
                if (result.Status) {
                    location.href = "Handled.aspx?css=1031";
                } else {
                    alert(result.Message);
                }
            }
        });
    });
    //审核基本信息    
    $(".passBasicInfo,.refuseLoan,.backBasicInfo").click(function () {

        var flag = false;
        $('textarea:enabled').each(function (index, item) {
            flag = CheckSpecificKey($(item).val());
            if (flag) {
                return false;
            }
        });
        if (flag) {
            return false;
        }
        if ($(this).attr("data-state") != "BackBasicInfo" && $("#displayMode").attr("data-total") !== "True") {
            //银行流水信息必须大于6条
            if ($("#tbFlow .rowFlow").length < 6) {
                alert("银行流水信息必须大于6条!");
                $("#procInfo").click();
                if ($("#tabRunning").css("display") == "none") {
                    $("#bankRunning").trigger("click");
                }

                return false;
            }
            else if (BankRunning < 6) {
                alert("请保存银行流水信息!");
                $("#procInfo").click();
                $("#bankRunning").trigger("click");
                return false;
            }
            var goOn = true;
            $.each($("#verifyList").find(".openLayout"), function (index, item) {
                //var $required = $("#auth" + $(this).attr("data-authid")).attr("data-required");
                var $verified = $(item).attr("data-verified");  //$required === "true" && 
                if ($verified !== "true") {
                    goOn = false;
                    return false;
                }
            });
            if (!goOn) {
                alert("有未通过的认证，请检查！");
                $("#procInfo").click();
                return;
            }
        }
        var data = { OrderId: $orderId, Type: 9, _: Math.random() };
        data.AuditStatus = $(this).attr("data-state");
        data.AuditOpinion = $(".verifyOpinion:eq('" + $index + "')").find("textarea").val().trim();
        data.WorkContactOpinion = $("#workContactOpinion").val().trim();
        data.FamilyContactOpinion = $("#familyContactOpinion").val().trim();
        data.EmergContactOpinion = $("#emergContactOpinion").val().trim();
        if (!data.WorkContactOpinion) {
            $("#basicInfo").click();
            $("#hideWorkInfo:contains('展开详情')").click();
            $("#workContactOpinion").focus();
            return;
        }
        if (!data.FamilyContactOpinion) {
            $("#basicInfo").click();
            $("#hideFamilyInfo:contains('展开详情')").click();
            $("#familyContactOpinion").focus();
            return;
        }
        if (!data.EmergContactOpinion) {
            $("#basicInfo").click();
            $("#hideEmergLinkInfo:contains('展开详情')").click();
            $("#emergContactOpinion").focus();
            return;
        }
        if (!data.AuditOpinion) {
            $("#basicInfo").click();
            $(".verifyOpinion:eq('" + $index + "')").find("textarea").focus();
            return;
        }
        $.ajax({
            url: "../Handler/LoanProductOrderHandler.ashx",
            type: "post",
            dataType: "json",
            data: data,
            async: true,
            cache: false,
            success: function (result) {
                if (result.Status) {
                    alert(result.Message);
                    $(".passBasicInfo,.backBasicInfo").hide();
                    if (data.Passed && $("#displayMode").attr("data-total") === "True") {
                        $("#verified").val("true");
                        $("#provInfo").click();
                    }
                    else {
                        location.href = "Handled.aspx?css=1031";
                    }
                } else {
                    alert(result.Message);
                }
            }
        });
    });

    $(".btnInfoPreserve").click(function () {
        //确定办法定种类
        var species = $(this).attr("data-type");
        var opinion = $.trim($(this).parent().prev().find("textarea").val());
        //alert(opinion);
        if (opinion.length == 0) {
            alert("保存信息不能为空！");
            return false;
        }
        $.ajax({
            url: "../Handler/LoanProductOrderHandler.ashx",
            type: "post",
            dataType: "json",
            data: { InfoOpinion: opinion, OrderId: $orderId, Species: species, Type: 23, _: Math.random() },
            async: true,
            cache: false,
            complete: function () {
            },
            success: function (result) {
                if (result.Status) {
                    alert(result.Message);
                } else {
                    alert(result.Message);
                }
            }
        });
    });

    //审核上传文件资料
    $("#passFile,#backFile").click(function () {
        var itemId = $("#itemId").val();
        if (!itemId || itemId <= 0) {
            return;
        }
        var data = { Type: 5, ItemId: itemId, _: Math.random() };
        data.Passed = $(this).attr("data-state") === "true";
        if (!data.Passed) {
            var $opinion = $("#fileOpinion").val().trim();
            if (!$opinion) {
                $("#fileOpinion").show().focus();
                return;
            } else {
                data.Opinion = $opinion;
            }
        }
        $.ajax(
            {
                url: "../Handler/LoanProductOrderHandler.ashx",
                type: "post",
                dataType: "json",
                data: data,
                async: true,
                cache: false,
                complete: function () {
                },
                success: function (result) {
                    if (result.Status) {
                        var authId = $("#authId").val();
                        var verifyStatus = data.Passed ? "审核已通过" : "审核未通过";
                        $("#auth" + authId).find(".verifyStatus").text(verifyStatus);
                        $("#auth" + authId).find(".openLayout").attr("data-passed", data.Passed);
                        $("#auth" + authId).find(".openLayout").attr("data-verified", data.Passed);
                        $("#auth" + authId).find(".openLayout").attr("data-opinion", data.Opinion);
                        $("#fileListModal .close").click();
                        if (!data.Passed) {
                            $(".passBasicInfo").hide();
                        }
                        var allowPass = true;
                        $.each($("#verifyList").children("div"), function (index, item) {
                            if ($(item).find(".openLayout").attr("data-verified") === "false") {
                                allowPass = false;
                                return false;
                            }
                        });
                        $(".passBasicInfo").css("display", allowPass ? "inline" : "none")
                    } else {
                        alert(result.Message);
                    }
                }
            });
    });

    //提交批核项目
    $("#submit").click(function () {
        var errorNode = null;
        $.each($("#orderData .text"), function (index, item) {
            if (!$(item).val()) {
                errorNode = $(item);
                var name = $(item).attr("data-name");
                $(item).next(".error").text(name + "不能为空");
                return false;
            }
        });
        if (errorNode) {
            return;
        }
        var data = serializer.Serialize($("#orderData"));
        data.OrderId = $orderId;
        data.IsOpen = $(".isOpen")[0].checked;
        data.IsCoborrowLoan = $(".isCoborrowLoan")[0].checked;
        data.Type = 12;
        data.IsAccordanceProduct = $(".isAccordanceProduct")[0].checked;
        data.AuditOpinion = $(".verifyOpinion:eq('" + $index + "')").find("textarea").val().trim();
        data.WorkContactOpinion = $("#workContactOpinion").val().trim();
        data.FamilyContactOpinion = $("#familyContactOpinion").val().trim();
        data.EmergContactOpinion = $("#emergContactOpinion").val().trim();
        data.MonthFee = $("select[name = Term]").find("option:selected").attr("data-MonthFee");
        //判断是否是联名借款
        if ($(".isCoborrowLoan")[0].checked) {
            var coborrowId = $("select[name=CoborrowId]").val();
            if (coborrowId == "-1") {
                var OtherCoborrow = $(".OtherCoborrowName").val();
                if (OtherCoborrow == "") {
                    $(".OtherCoborrowName").next(".error").text("其他联名借款人不能为空");
                    return;
                }
                else {
                    data.CoborrowName = OtherCoborrow;
                }
            }
            else {
                data.CoborrowName = $("select[name=CoborrowId] option:selected").text();
            }
        }
        data.CoborrowName = data.CoborrowName + "," + $(".ddlCoborrowLoan").val()
        //判断是否更换产品
        if ($(".isAccordanceProduct")[0].checked) {
            data.AccordanceProduct = $("select.ddlAccordanceProduct option:selected").text() + "," + $("select.ddlAccordanceProduct").val();
        }
        $.ajax({
            url: "../Handler/LoanProductOrderHandler.ashx",
            type: "post",
            dataType: "json",
            data: data,
            async: true,
            cache: false,
            complete: function () {
            },
            success: function (result) {
                if (result.Status) {
                    location.href = "Handled.aspx?css=1031";
                } else {
                    alert(result.Message);
                }
            }
        });
    });

    //借款是否是联名借款
    $("input[type='radio'][name=IsCoborrowLoan]").click(function () {
        var isCoborrowLoan = $(this).val();
        if (isCoborrowLoan == "true") {
            $.ajax({
                type: "post",
                url: "../Handler/LoanUserInfo.ashx",
                dataType: "json",
                data: { type: 7, UserId: $userId },
                async: false,
                cache: true,
                complete: function () {
                },
                success: function (result) {
                    if (result.Status == true) {
                        if (result.Count == 0) {
                            alert("请先完善紧急联系人信息!");
                            return;
                        }
                        var str = "";
                        $(result.Data).each(function (i, e) {
                            str += "<option value='" + i + "'>" + e + "</option>";
                        });
                        str += "<option value='-1'>其他</option>";
                        $("select[name = CoborrowId]").css("display", "inline").html(str);
                    }
                    else {
                        alert(result.Message);
                    }
                }
            });
        }
        else {
            $("select[name = CoborrowId]").css("display", "none");
            $("input.OtherCoborrowName").css("display", "none");
        }

    });

    //联名借款人选择的是其他时，显示输入文本框OtherCoborrowName
    $("select[name = CoborrowId]").change(function () {
        var coborrowId = $("select[name=CoborrowId]").val();
        if (coborrowId == "-1") {
            $("input.OtherCoborrowName").css("display", "inline");
        }
        else {
            $("input.OtherCoborrowName").css("display", "none");
        }
    });

    //是否更换产品
    $("input[type='radio'][name=IsAccordanceProduct]").click(function () {
        var isAccordanceProduct = $(this).val();
        if (isAccordanceProduct == "true") {
            $.ajax({
                type: "post",
                url: "../Handler/ProductHandler.ashx",
                dataType: "json",
                data: { Type: 0, ProductType: 2 },
                async: false,
                cache: true,
                complete: function () {
                },
                success: function (result) {
                    var str = "";
                    $(result).each(function (i, e) {
                        str += '<option value="' + e.ProductId + '">' + e.ProductName + '</option>';
                    });
                    $("select[name = AccordanceProduct]").css("display", "inline").html(str);
                }
            });
            var type = $("select.ddlAccordanceProduct").val();
            getLoanProductFee(type);
        }
        else {
            getLoanProductFee(productTypeId);
            $("select[name = AccordanceProduct]").css("display", "none");
        }
    });

    //预加载银行流水信息（必须首次就加载出来）
    loadinfo.Url = "../Handler/LoanBankRunningHandler.ashx";
    loadinfo.type = 1;
    loadinfo.CallBack = function (data) {
        if (data != null) {
            $.each(data, function (index, item) {
                if (item.Seq.indexOf("totalFlow") < 0 && item.Seq.indexOf("avgFlow") < 0) {
                    $("#FlowTemplate").tmpl().insertBefore($("#trFlowTotal"));
                    new JSONSerializer().DeSerialize($("tr.rowFlow:last"), item);
                    BankRunning++;
                }
                else if (item.Seq.indexOf("avgFlow") < 0) {
                    //单独绑定总计信息
                    if (item.Salary) {
                        $("#txtAccount1Total").text(item.Salary);
                    }
                    if (item.Bonus) {
                        $("#txtAccount2Total").text(item.Bonus);
                    }
                    if (item.Personal) {
                        $("#txtAccount3Total").text(item.Personal);
                    }
                    if (item.ForPublic) {
                        $("#txtAccount4Total").text(item.ForPublic);
                    }
                    $("#flowOther").val(item.Other);
                }
                else {//单独绑定月均信息
                    if (item.Salary) {
                        $("#txtAccount1Avg").text(item.Salary);
                    }
                    if (item.Bonus) {
                        $("#txtAccount2Avg").text(item.Bonus);
                    }
                    if (item.Personal) {
                        $("#txtAccount3Avg").text(item.Personal);
                    }
                    if (item.ForPublic) {
                        $("#txtAccount4Avg").text(item.ForPublic);
                    }
                }
            })
        }
    };
    loadinfo.GetRelationInfo();

    //点击TAB（批核信息）预加载各类关联信息
    $("#procInfo").one("click", function () {

        //预加载申请人照会信息

        loadinfo.Url = "../Handler/LoanReplyNoteHandler.ashx";
        loadinfo.type = 1;
        loadinfo.CallBack = function (data) {
            if (data != null) {
                editor.html(decodeURI(data.LoanReplyMemo));
                //$("textarea[name=LoanReplyMemo]").val(decodeURI(data.LoanReplyMemo));
                //alert(decodeURI(data.LoanReplyMemo));
                new JSONSerializer().DeSerialize($("#tblNode"), data);
            }
        };
        loadinfo.GetRelationInfo();



        //预加载企业信息·
        loadinfo.Url = "../Handler/CompanyInfoHandler.ashx";
        loadinfo.type = 1;
        loadinfo.CallBack = function (data) {
            if (data != null) {
                new JSONSerializer().DeSerialize($("#tblBussiness"), data);
                //单独处理成立时间
                if (data.FoundingTime != null) {
                    $("input[name=FoundingTime]").val(ChangeDateFormat(data.FoundingTime));
                }
            }
            else {
                $("input[name=LegalRep]").val(legalperson);
                $("input[name=CompanyName]").val(companyName);
                $("input[name=CompanyAddress]").val(complayAddress);

            }
        };
        loadinfo.GetRelationInfo();

        //预加载信用卡信息
        loadinfo.Url = "../Handler/LoanCreditCardHandler.ashx";
        loadinfo.type = 1;
        loadinfo.CallBack = function (data) {
            if (data != null) {
                $.each(data, function (index, item) {
                    if (item.Seq.indexOf("总计") < 0) {
                        $(".btnAddCridet").click();
                        new JSONSerializer().DeSerialize($("tr.rowCridet:last"), item);
                    }
                    else { //单独绑定总计信息
                        if (item.LineCredit) {
                            $("#txtCridetTotal").text(item.LineCredit);
                        }
                        if (item.Overdraft) {
                            $("#txtOverDraftTotal").text(item.Overdraft);
                        }
                        if (item.OverdueCount) {
                            $("#txtOverdueCountTotal").text(item.OverdueCount);
                        }
                        $("#inputOther").val(item.Other);
                    }
                })
            }
        };
        loadinfo.GetRelationInfo();

        //预加载借款情况信息
        loadinfo.Url = "../Handler/LoanInfoHandler.ashx";
        loadinfo.type = 1;
        loadinfo.CallBack = function (data) {
            if (data != null) {
                $.each(data, function (index, item) {
                    if (item.Seq.indexOf("total") < 0) {
                        $(".btnAddLoan").click();
                        new JSONSerializer().DeSerialize($("tr.rowLoan:last"), item);
                        //单独绑定到期日
                        $("tr.rowLoan:last").find("input[name=DueDate]").val(ChangeDateFormat(item.DueDate));
                    }
                    else { //单独绑定总计信息
                        if (item.Total) {
                            $("#txtLoanTotal").text(item.Total);
                        }
                        if (item.Balance) {
                            $("#txtBanlanceTotal").text(item.Balance);
                        }
                        if (item.RepayPerMonth) {
                            $("#txtPerRepayTotal").text(item.RepayPerMonth);
                        }

                        $("#loanOther").val(item.Other);
                    }
                })
            }
        };
        loadinfo.GetRelationInfo();

        //预加载客户过往记录信息
        loadinfo.Url = "../Handler/LoanProductOrderHandler.ashx";
        loadinfo.type = 24;
        loadinfo.Data.OrderId = $orderId;
        loadinfo.Data.IDCard = idCard;
        loadinfo.CallBack = function (data) {
            if (data != null) {
                $.each(data, function (index, item) {
                    $("#CustomRecordTemplate").tmpl(item).appendTo("#tbRecord");
                })
            }
        };
        loadinfo.GetRelationInfo();

        ////只有初审才能编辑各类关联信息
        //if ($("#displayMode").attr("data-disabled") === "True") {
        //    //申请人照会信息
        //    $(".saveNode").css("display", "none");
        //    $("#tblNode input,#tblNode textarea").attr("readonly", true);

        //    //信用卡信息
        //    $(".btnAddCridet,.btnDelCridet,.btnSaveCridet").css("display", "none");
        //    $("#tbCridet input").attr("readonly", true);


        //    //借款情况信息
        //    $(".btnAddLoan,.btnDelLoan,.btnSaveLoan").css("display", "none");
        //    $("#tbLoan input").attr("readonly", true);

        //    //企业信息
        //    $(".saveBusiness").css("display", "none");
        //    $("#tblBussiness input").attr("readonly", true);


        //    //银行流水信息
        //    $(".btnAddFlow,.btnDelFlow,.btnSaveFlow").css("display", "none");
        //    $("#tbFlow input").attr("readonly", true);

        //}
    });

    $("#provInfo").one("click", function () {
        if ($(".isAccordanceProduct")[0].checked) {
            var type = $("select.ddlAccordanceProduct").val();
            getLoanProductFee(type);
        }
        else {
            getLoanProductFee(productTypeId);
        }
    });

    //当更换产品时联动效果
    $("select.ddlAccordanceProduct").change(function () {
        var type = $(this).val();
        getLoanProductFee(type);
    })
});

//动态获取借款产品费率
function getLoanProductFee(typeId) {
    $.ajax({
        type: "post",
        url: "../Handler/LoanProductOrderHandler.ashx",
        dataType: "json",
        data: { Type: 25, ProductId: typeId },
        async: true,
        cache: true,
        complete: function () { },
        success: function (result) {
            if (result.Status) {
                var str = "";
                $(result.Data).each(function (i, e) {
                    str += '<option  data-MonthFee=' + e.MonthFee + ' value="' + e.LoanMonths + '">' + e.LoanMonths + '</option>';
                });
                $("select[name = Term]").html(str);
            }
        }
    });
}

//更新进度条
function updateProgress(data) {
    var total = 0, count = 5;
    if (data.Order) {
        total += 100 / count;
    }
    if (data.Family) {
        total += 100 / count;
    }
    if (data.User) {
        total += 100 / count;
    }
    if (data.Work) {
        total += 100 / count;
    }
    if (data.LoanItems && data.LoanItems.length > 0) {
        total += 100 / count;
    }
    total = parseInt(total);
    $(".progressBar").text(total + "%").css("width", total + "%");
}

//加载审核文件项目
function loadVerifyFiles(productId) {
    $.getJSON("../Handler/ProductHandler.ashx",
        { Id: productId, Type: 5 },
        function (result) {
            if (result.Status) {
                $("#verifyList").empty();
                $.each(result.Data, function (index, item) {
                    $("#AuthentionTemplate").tmpl(item).appendTo("#verifyList").find(".openLayout").click(function () {
                        $("#fileOpinion").val("");
                        var authId = $(this).attr("data-authid");
                        $("#authId").val(authId);
                        $("#itemId").val($(this).attr("data-itemid"));
                        $("#filelist").empty();
                        $("#filelist").html(filesHtml["content" + authId]);
                        loadZoomScript();
                        $("#fileOpinion").hide().empty();
                        if ($("#displayMode").attr("data-disabled") === "False" && $(this).attr("data-passed") == "false") {
                            if ($(this).attr("data-opinion")) {
                                $("#fileOpinion").show().val($(this).attr("data-opinion"));
                            }

                            $("#backFile,#passFile").show();
                        }
                        else if ($("#displayMode").attr("data-disabled") === "False" && $(this).attr("data-passed") == "true") {
                            $("#backFile,#passFile").show();
                        }
                        else {
                            $("#backFile,#passFile").hide();
                        }
                    });
                });
                updateItemsStatus();
            } else {
                alert(result.Message);
            }
        });
}
//添加预览脚本
function loadZoomScript() {
    $("#zoomScript").remove();
    $("#zoom").remove();
    var myScript = document.createElement("script");
    myScript.type = "text/javascript";
    myScript.id = "zoomScript";
    myScript.src = "../Plugins/gurdeZoom/js/zoom.min.js";
    document.body.appendChild(myScript);
}
//更新审核信息
function updateItemsStatus() {
    $.each(loanItems, function (index, item) {
        var dom = $("#verifyList div[data-authid='" + item.AuthId + "']");
        if (dom) {
            dom.attr("uploaded", true);
            dom.find(".openLayout").attr("data-itemid", item.LoanItemId);
            dom.find(".openLayout").attr("data-opinion", item.VerifyOpinion);
            dom.find(".openLayout").attr("data-passed", item.Passed);
            if (filesHtml["content" + item.AuthId]) {
                var matches = filesHtml["content" + item.AuthId].match(/src=\"(.*?)\"/);
                if (matches) {
                    dom.find(".uploadStatus").text("资料已上传").end().find(".openLayout").show();
                    if (item.Passed) {
                        dom.find(".verifyStatus").text("已通过审核").end().find(".openLayout").attr("data-verified", true);
                    }
                    else {
                        if (item.VerifyOpinion != "" && item.VerifyOpinion != null) {
                            dom.find(".verifyStatus").text("审核未通过").end().find(".openLayout").attr("data-verified", false);
                        }
                    }
                }
            }
        }
    });
    if ($("#displayMode").attr("data-reconsider") === "True") {
        $("#verifyList span.verifyStatus").css("display", "none");
    }
    $("#verifyList").children("div[data-required='false']:not('[uploaded]')").remove();
}

//信用卡信息添加一行
$(".btnAddCridet").click(function () {
    $("#CridetTemplate").tmpl().insertBefore($("#trCridetTotal"));
});

//删除信用卡信息
$(".btnDelCridet").click(function () {
    $("#tbCridet [name=chkCridet]:checkbox").each(function (i) {
        if ($(this).is(":checked")) {
            $(this).parent().parent().remove();
        }
    });
    if ($("#tbCridet .rowCridet").length == 0) {
        $("#txtCridetTotal").text("");
        $("#txtOverDraftTotal").text("");
        $("#txtOverdueCountTotal").text("");
    }
    $(".txtCreditAmount").change();
    $(".txtOverDraft").change();
    $(".txtOverdueCount").change();
});

//是否全选信用卡信息
$("#chkCridetAll").click(function () {
    var $CridetChecked = $(this).is(":checked");
    if ($CridetChecked) {
        $("[name=chkCridet]:checkbox").prop("checked", true);
    }
    else {
        $("[name=chkCridet]:checkbox").prop("checked", false);
    }
});

//保存信用卡信息
$(".btnSaveCridet").bind("click", function () {
    //alert($("tr.rowCridet").length);
    var listCridet = new Array();
    $("tr.rowCridet").each(function () {
        var item = new Object();
        item.OrderId = $orderId;
        item.Seq = $(this).find(".txtSeq").val();
        item.CardIssue = $(this).find(".txtCardIssue").val();
        item.LineCredit = $(this).find(".txtLineCredit").val();
        item.OverDraft = $(this).find(".txtOverDraft").val();
        item.OverdueCount = $(this).find(".txtOverdueCount").val();
        item.Overdue = $(this).find(".txtOverdue").val();
        listCridet.push(item);
    });
    var total = new Object();
    total.OrderId = $orderId;
    total.Seq = "总计";
    total.LineCredit = $("#txtCridetTotal").text();
    total.OverDraft = $("#txtOverDraftTotal").text();
    total.OverdueCount = $("#txtOverdueCountTotal").text();
    total.Other = $("#inputOther").val();
    listCridet.push(total);
    //alert(JSON.stringify(listCridet));
    $.ajax({
        type: "post",
        url: "../Handler/LoanCreditCardHandler.ashx",
        dataType: "json",
        data: { Type: 0, OrderId: $orderId, CradInfo: JSON.stringify(listCridet), _: Math.random() },
        async: true,
        cache: false,
        complete: function () {
        },
        success: function (result) {
            alert(result.Message);
        }
    });

});

//借款信息添加一行
$(".btnAddLoan").click(function () {
    $("#LoanTemplate").tmpl().insertBefore($("#trLoanTotal"));
    $("tr.rowLoan  .txtDueDate").unbind("blur").bind("blur", function () {
        if (!$(this).val().match(/^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})$/)) {
            var reg = /^[0-9]{4}[0-1]{1}[0-9]{1}[0-3]{1}[0-9]{1}$/;
            var result = $(this).val().match(reg);
            if (result == null) {
                alert("请输入格式正确的日期\n\r日期格式：yyyymmdd  \n\r例如：20080808\n\r");
                return false;
            }
            var time = $(this).val().substr(0, 4) + "-" + $(this).val().substr(4, 2) + "-" + $(this).val().substr(6, 2);
            $(this).val(time);
        }
    });

});

//删除借款信息
$(".btnDelLoan").click(function () {
    $("#tbLoan [name=chkLoan]:checkbox").each(function (i) {
        if ($(this).is(":checked")) {
            $(this).parent().parent().remove();
        }
    });
    if ($("#tbLoan .rowLoan").length == 0) {
        $("#txtLoanTotal").text("");
        $("#txtBanlanceTotal").text("");
        $("#txtPerRepayTotal").text("");
    }
    $(".txtLoan").change();
    $(".txtBanlance").change();
    $(".txtPerRepay").change();
});

//是否全选借款信息
$("#chkLoanAll").click(function () {
    var $LoanChecked = $(this).is(":checked");
    if ($LoanChecked) {
        $("[name=chkLoan]:checkbox").prop("checked", true);
    }
    else {
        $("[name=chkLoan]:checkbox").prop("checked", false);
    }
});

//保存借款情况信息
$(".btnSaveLoan").bind("click", function () {
    var reg = /^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})$/;
    var errorDate = false;
    $("tr.rowLoan .txtDueDate").each(function () {
        var result = $(this).val().match(reg);
        if (result == null) {
            errorDate = true;
            return;
        }
    });
    if (errorDate) {
        alert("请输入格式正确的日期\n\r日期格式：yyyymmdd  \n\r例如：20080808\n\r");
        return false;
    }
    var listLoan = new Array();
    $("tr.rowLoan").each(function () {
        var item = new Object();
        item.OrderId = $orderId;
        item.Seq = $(this).find(".txtSeq").val();
        item.CardIssue = $(this).find(".txtCardIssue").val();
        item.CreditMechanism = $(this).find(".txtCreditMechanism").val();
        item.Property = $(this).find(".txtProperty").val();
        item.Total = $(this).find(".txtTotal").val();
        var dueDate = $(this).find(".txtDueDate").val();
        item.Balance = $(this).find(".txtBanlance").val();
        item.DueDate = $(this).find(".txtDueDate").val();;
        item.RepayPerMonth = $(this).find(".txtRepayPerMonth").val();
        item.Overdue = $(this).find(".txtOverdue").val();
        listLoan.push(item);
    });
    var total = new Object();
    total.OrderId = $orderId;
    total.Seq = "total";
    total.Total = $("#txtLoanTotal").text();
    total.Balance = $("#txtBanlanceTotal").text();
    total.RepayPerMonth = $("#txtPerRepayTotal").text();
    total.Other = $("#loanOther").val();
    listLoan.push(total);
    $.ajax({
        type: "post",
        dataType: "json",
        url: "../Handler/LoanInfoHandler.ashx",
        data: { type: 0, OrderId: $orderId, LoanInfo: JSON.stringify(listLoan), _: Math.random() },
        async: true,
        cache: false,
        complete: function () {
        },
        success: function (result) {
            alert(result.Message);
        }
    });
})

// 
$("input[name='FoundingTime']").blur(function () {

    if (!$(this).val().match(/^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})$/)) {
        var reg = /^[0-9]{4}[0-1]{1}[0-9]{1}[0-3]{1}[0-9]{1}$/;
        var result = $(this).val().match(reg);
        if (result == null) {
            alert("请输入格式正确的日期\n\r日期格式：yyyymmdd  \n\r例如：20080808\n\r");
            return false;
        }
        var time = $(this).val().substr(0, 4) + "-" + $(this).val().substr(4, 2) + "-" + $(this).val().substr(6, 2);
        $(this).val(time);
    }
});

//保存企业信息
$(".saveBusiness").bind("click", function () {

    if ($("input[name='FoundingTime']").val().trim().length != 0) {
        var reg = /^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})$/;

        var result = $("input[name='FoundingTime']").val().match(reg);
        if (result == null) {
            alert("请输入格式正确的日期\n\r日期格式：yyyymmdd  \n\r例如：20080808\n\r");
            return false;
        }
    }

    var tblData = serializer.Serialize($("#tblBussiness")[0]);
    tblData.OrderId = $orderId;
    tblData.type = 0;
    tblData._ = Math.random()

    $.ajax({
        type: "post",
        dataType: "json",
        url: "../Handler/CompanyInfoHandler.ashx",
        data: tblData,
        async: true,
        cache: false,
        complete: function () { },
        success: function (result) {
            alert(result.Message);
        }
    });


});

//保存照会信息
$(".saveNode").bind("click", function () {
    //alert(editor.text());
    var tblNode = serializer.Serialize($("#tblNode")[0]);
    tblNode.OrderId = $orderId;
    tblNode.LoanReplyMemo = encodeURI(editor.text());//$("textarea[name=LoanReplyMemo]").val().trim();
    tblNode.type = 0;
    tblNode._ = Math.random();
    $.ajax({
        type: "post",
        dataType: "json",
        url: "../Handler/LoanReplyNoteHandler.ashx",
        data: tblNode,
        async: true,
        cache: false,
        complete: function () { },
        success: function (result) {
            alert(result.Message);
        }
    });

});


//银行流水添加一行
$(".btnAddFlow").click(function () {
    $("#FlowTemplate").tmpl().insertBefore($("#trFlowTotal"));
});

//删除银行流水信息
$(".btnDelFlow").click(function () {
    $("#tbFlow [name=chkFlow]:checkbox").each(function (i) {
        if ($(this).is(":checked")) {
            $(this).parent().parent().remove();
        }
    });
    if ($("#tbFlow .rowFlow").length == 0) {
        $("#txtAccount1Total").text("");
        $("#txtAccount2Total").text("");
        $("#txtAccount3Total").text("");
        $("#txtAccount4Total").text("");
        $("#txtAccount1Avg").text("");
        $("#txtAccount2Avg").text("");
        $("#txtAccount3Avg").text("");
        $("#txtAccount4Avg").text("");
    }
    $(".txtAccount1").change();
    $(".txtAccount2").change();
    $(".txtAccount3").change();
    $(".txtAccount4").change();
});

//是否全选银行流水信息
$("#chkFlowAll").click(function () {
    var $FlowChecked = $(this).is(":checked");
    if ($FlowChecked) {
        $("[name=chkFlow]:checkbox").prop("checked", true);
    }
    else {
        $("[name=chkFlow]:checkbox").prop("checked", false);
    }
});

//保存银行流水信息
$(".btnSaveFlow").bind("click", function () {
    var listFlow = new Array();
    BankRunning = 0;
    $("tr.rowFlow").each(function () {
        var item = new Object();
        item.OrderId = $orderId;
        item.Seq = $(this).find(".txtSeq").val();
        item.Salary = $(this).find(".txtSalary").val();
        item.Bonus = $(this).find(".txtBonus").val();
        item.Personal = $(this).find(".txtPersonal").val();
        item.ForPublic = $(this).find(".txtPublic").val();
        listFlow.push(item);
        BankRunning++;
    });
    //单独绑定月均，大于等于6条才会保存
    if (listFlow.length > 5) {
        var avg = new Object();
        avg.OrderId = $orderId;
        avg.Seq = "avgFlow";
        avg.Salary = $("#txtAccount1Avg").text();
        avg.Bonus = $("#txtAccount2Avg").text();
        avg.Personal = $("#txtAccount3Avg").text();
        avg.ForPublic = $("#txtAccount4Avg").text();
        listFlow.push(avg);
    }
    //单独绑定总计
    var total = new Object();
    total.OrderId = $orderId;
    total.Seq = "totalFlow";
    total.Salary = $("#txtAccount1Total").text();
    total.Bonus = $("#txtAccount2Total").text();
    total.Personal = $("#txtAccount3Total").text();
    total.ForPublic = $("#txtAccount4Total").text();
    total.Other = $("#flowOther").val();
    listFlow.push(total);

    //avg.Other = $("#flowOther").val();

    $.ajax({
        type: "post",
        url: "../Handler/LoanBankRunningHandler.ashx",
        dataType: "json",
        data: { Type: 0, OrderId: $orderId, RunningInfo: JSON.stringify(listFlow), _: Math.random() },
        async: true,
        cache: false,
        complete: function () {
        },
        success: function (result) {
            alert(result.Message);
        }
    });
});

String.prototype.replaceAll = function (reallyDo, replaceWith, ignoreCase) {
    if (!RegExp.prototype.isPrototypeOf(reallyDo)) {
        return this.replace(new RegExp(reallyDo, (ignoreCase ? "gi" : "g")), replaceWith);
    } else {
        return this.replace(reallyDo, replaceWith);
    }
}

//预览申请人照会信息
$(".previewNode").bind("click", function () {
    var tblNode = serializer.Serialize($("#tblNode")[0]);
    var strLoanReplyMemo = editor.text();
    //如果有图片则添加样式
    if (strLoanReplyMemo.indexOf("<img") != -1) {
        strLoanReplyMemo = strLoanReplyMemo.replaceAll("<img", "<img style='width:100%;'");
    }
    $("#divLoanReplyMemo").html(strLoanReplyMemo);
    serializer.DeSerializeToSpan($("#tblPreviewNode"), tblNode);
});
//授信总计
$("#tbCridet").delegate(".txtCreditAmount", "change", function () {
    var $CreditAmountTotal = 0;
    $(".txtCreditAmount").each(function (i) {
        $CreditAmountTotal += parseFloat($(this).val());
    });
    if (isNaN($CreditAmountTotal)) {
        $("#txtCridetTotal").text("");
    }
    else {
        $("#txtCridetTotal").text($CreditAmountTotal);
    }
});

//透支总计
$("#tbCridet").delegate(".txtOverDraft", "change", function () {
    var $OverdraftTotal = 0;
    $(".txtOverDraft").each(function (i) {
        $OverdraftTotal += parseFloat($(this).val());
    });
    if (isNaN($OverdraftTotal)) {
        $("#txtOverDraftTotal").text("");
    }
    else {
        $("#txtOverDraftTotal").text($OverdraftTotal);
    }
});

//逾期次数总计
$("#tbCridet").delegate(".txtOverdueCount", "change", function () {
    var $Total = 0;
    $(".txtOverdueCount").each(function (i) {
        $Total += parseFloat($(this).val());
    });
    if (isNaN($Total)) {
        $("#txtOverdueCountTotal").text("");
    }
    else {
        $("#txtOverdueCountTotal").text($Total);
    }
});

//未结借款总额总计
$("#tbLoan").delegate(".txtLoan", "change", function () {
    var $Total = 0;
    $(".txtLoan").each(function (i) {
        $Total += parseFloat($(this).val());
    });
    if (isNaN($Total)) {
        $("#txtLoanTotal").text("");
    }
    else {
        $("#txtLoanTotal").text($Total);
    }
});

//未结借款余额总计
$("#tbLoan").delegate(".txtBanlance", "change", function () {
    var $Total = 0;
    $(".txtBanlance").each(function (i) {
        $Total += parseFloat($(this).val());
    });
    if (isNaN($Total)) {
        $("#txtBanlanceTotal").text("");
    }
    else {
        $("#txtBanlanceTotal").text($Total);
    }
});

//未结借款月供总计
$("#tbLoan").delegate(".txtPerRepay", "change", function () {
    var $Total = 0;
    $(".txtPerRepay").each(function (i) {
        $Total += parseFloat($(this).val());
    });
    if (isNaN($Total)) {
        $("#txtPerRepayTotal").text("");
    }
    else {
        $("#txtPerRepayTotal").text($Total);
    }
});

//银行流水账户1总计
$("#tbFlow").delegate(".txtAccount1", "change", function () {
    var $Total = 0;
    $(".txtAccount1").each(function (i) {
        $Total += parseFloat($(this).val());
    });
    if (isNaN($Total)) {
        $("#txtAccount1Total").text("");
    }
    else {
        $("#txtAccount1Total").text($Total);
    }
});

//银行流水账户2总计
$("#tbFlow").delegate(".txtAccount2", "change", function () {
    var $Total = 0;
    $(".txtAccount2").each(function (i) {
        $Total += parseFloat($(this).val());
    });
    if (isNaN($Total)) {
        $("#txtAccount2Total").text("");
    }
    else {
        $("#txtAccount2Total").text($Total);
    }
});

//银行流水账户3总计
$("#tbFlow").delegate(".txtAccount3", "change", function () {
    var $Total = 0;
    $(".txtAccount3").each(function (i) {
        $Total += parseFloat($(this).val());
    });
    if (isNaN($Total)) {
        $("#txtAccount3Total").text("");
    }
    else {
        $("#txtAccount3Total").text($Total);
    }
});

//银行流水账户4总计
$("#tbFlow").delegate(".txtAccount4", "change", function () {
    var $Total = 0;
    $(".txtAccount4").each(function (i) {
        $Total += parseFloat($(this).val());
    });
    if (isNaN($Total)) {
        $("#txtAccount4Total").text("");
    }
    else {
        $("#txtAccount4Total").text($Total);
    }
});

//银行流水账户1月均
$("#tbFlow").delegate(".txtAccount1", "change", function () {
    var $Total = 0;
    var $min = parseFloat($(this).val());
    var $max = parseFloat($(this).val());
    var $len = $(".txtAccount1").length - 2;
    if ($len > 3) {
        $(".txtAccount1").each(function (i) {
            $SelfVal = parseFloat($(this).val());
            if ($SelfVal > $max) {
                $max = $SelfVal;
            }
            if ($SelfVal < $min) {
                $min = $SelfVal;
            }
            $Total += $SelfVal;
        });
        $Total = ($Total - $max - $min) / $len;
        if (!isNaN($Total)) {
            $("#txtAccount1Avg").text($Total);
        }
        else {
            $("#txtAccount1Avg").text("");
        }
    }
    else {
        $("#txtAccount1Avg").text("");
    }
});

//银行流水账户2月均
$("#tbFlow").delegate(".txtAccount2", "change", function () {
    var $Total = 0;
    var $min = parseFloat($(this).val());
    var $max = parseFloat($(this).val());
    var $len = $(".txtAccount2").length - 2;
    if ($len > 3) {
        $(".txtAccount2").each(function (i) {
            $SelfVal = parseFloat($(this).val());
            if ($SelfVal > $max) {
                $max = $SelfVal;
            }
            if ($SelfVal < $min) {
                $min = $SelfVal;
            }
            $Total += $SelfVal;
        });
        $Total = ($Total - $max - $min) / $len;
        if (!isNaN($Total)) {
            $("#txtAccount2Avg").text($Total);
        }
        else {
            $("#txtAccount2Avg").text("");
        }
    }
    else {
        $("#txtAccount2Avg").text("");
    }
});

//银行流水账户3月均
$("#tbFlow").delegate(".txtAccount3", "change", function () {
    var $Total = 0;
    var $min = parseFloat($(this).val());
    var $max = parseFloat($(this).val());
    var $len = $(".txtAccount3").length - 2;
    if ($len > 3) {
        $(".txtAccount3").each(function (i) {
            $SelfVal = parseFloat($(this).val());
            if ($SelfVal > $max) {
                $max = $SelfVal;
            }
            if ($SelfVal < $min) {
                $min = $SelfVal;
            }
            $Total += $SelfVal;
        });
        $Total = ($Total - $max - $min) / $len;
        if (!isNaN($Total)) {
            $("#txtAccount3Avg").text($Total);
        }
        else {
            $("#txtAccount3Avg").text("");
        }
    }
    else {
        $("#txtAccount3Avg").text("");
    }
});

//银行流水账户4月均
$("#tbFlow").delegate(".txtAccount4", "change", function () {
    var $Total = 0;
    var $min = parseFloat($(this).val());
    var $max = parseFloat($(this).val());
    var $len = $(".txtAccount4").length - 2;
    if ($len > 3) {
        $(".txtAccount4").each(function (i) {
            $SelfVal = parseFloat($(this).val());
            if ($SelfVal > $max) {
                $max = $SelfVal;
            }
            if ($SelfVal < $min) {
                $min = $SelfVal;
            }
            $Total += $SelfVal;
        });
        $Total = ($Total - $max - $min) / $len;
        if (!isNaN($Total)) {
            $("#txtAccount4Avg").text($Total);
        }
        else {
            $("#txtAccount4Avg").text("");
        }
    }
    else {
        $("#txtAccount4Avg").text("");
    }
});

//格式化日期
function ChangeDateFormat(cellval) {
    var date = new Date(parseInt(cellval.replace("/Date(", "").replace(")/", ""), 10));
    var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
    var currentDate = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
    return date.getFullYear() + "-" + month + "-" + currentDate;
}

//文本框禁止输入特殊字符
function CheckSpecificKey(input) {
    var specialKey = ['#', '$', '%', '^', '*', '"', '+', '\\']; //Specific Key list
    var flg = false;
    $.each(specialKey, function (key, val) {
        flg = (input.indexOf(val) >= 0);
        if (flg) {
            alert('请勿输入特殊字符: ' + val);
            return false;
        }
    });
    return flg;
}

//显示用户数据重复身份信息
function showUserRepeatIDCard(i) {
    $.ajax({
        url: "/Handler/IsUserInfoExistHandler.ashx",
        type: "get",
        dataType: "json",
        data: { type: 0, IDCard: i, orderId: $orderId, _: Math.random() },
        async: true,
        cache: false,
        complete: function () { },
        success: function (result) {
            if (result.Status) {
                $(".loanProductOrderList").empty();
                $.each(result.Data, function (index, item) {
                    //获取到所有的重复项目的订单
                    $("#LoanProductOrderTemplate").tmpl(item).appendTo($(".loanProductOrderList"));
                });
                $("#ModalLabel").html("查询的" + i + "身份在以下项目中有过记录");
            } else {
                $("#span_IDCard").html("身份证信息查询无重复记录!");
                $("#span_IDCard").css("color", "green");
                $("#span_IDCard").css("font-size", "12px");
            }
        },
        error: function (result) {
             
        }
    });
}

function showUserRepeatPhone(p) {
    $.ajax({
        url: "/Handler/IsUserInfoExistHandler.ashx",
        type: "get",
        dataType: "json",
        data: { type: 1, Phone: p, orderId: $orderId, _: Math.random() },
        async: true,
        cache: false,
        complete: function () { },
        success: function (result) {
            if (result.Status) {
                $(".loanProductOrderPhoneList").empty();
                $.each(result.Data, function (index, item) {
                    //获取到所有的重复项目的订单
                    $("#LoanProductOrderPhoneTemplate").tmpl(item).appendTo($(".loanProductOrderPhoneList"));
                });
                $("#ModalLabel_Phone").html("查询的" + p + "电话在以下项目中有过记录");
            } else {
                $("#span_Phone").html("电话信息查询无重复记录!");
                $("#span_Phone").css("color", "green");
                $("#span_Phone").css("font-size", "12px");
            }
        }
    });
}

function showUserRepeatCompanyName(n) {
    if (n == null || n == "") {
        $("#span_WorkName").html("");
        return;
    }

    $.ajax({
        url: "/Handler/IsUserInfoExistHandler.ashx",
        type: "get",
        dataType: "json",
        data: { type: 2, Name: n, orderId: $orderId, _: Math.random() },
        async: true,
        cache: false,
        complete: function () { },
        success: function (result) {
            if (result.Status) {
                $(".loanProductOrderWorkNameList").empty();
                $.each(result.Data, function (index, item) {
                    //获取到所有的重复项目的订单
                    $("#LoanProductOrderWorkNameTemplate").tmpl(item).appendTo($(".loanProductOrderWorkNameList"));
                });
                $("#ModalLabel_WorkName").html("查询的" + n + "在以下项目中有过记录");
            } else {
                $("#span_WorkName").html("单位信息查询无重复记录!");
                $("#span_WorkName").css("color", "green");
                $("#span_WorkName").css("font-size", "12px");
            }
        }
    });
}

function showUserRepeatWorkPhone(p) {
    if (p == null || p == "") {
        $("#span_WorkPhone").html("");
        return;
    }
    $.ajax({
        url: "/Handler/IsUserInfoExistHandler.ashx",
        type: "get",
        dataType: "json",
        data: { type: 1, Phone: p, orderId: $orderId, _: Math.random() },
        async: true,
        cache: false,
        complete: function () { },
        success: function (result) {
            if (result.Status) {
                $(".loanProductOrderWorkPhoneList").empty();
                $.each(result.Data, function (index, item) {
                    //获取到所有的重复项目的订单
                    $("#LoanProductOrderWorkPhoneTemplate").tmpl(item).appendTo($(".loanProductOrderWorkPhoneList"));
                });
                $("#ModalLabel_WorkPhone").html("查询的" + p + "电话在以下项目中有过记录");
            } else {
                $("#span_WorkPhone").html("电话信息查询无重复记录!");
                $("#span_WorkPhone").css("color", "green");
                $("#span_WorkPhone").css("font-size", "12px");
            }
        }
    });
}

function showUserRepeatAddressPhone(p) {
    
    if (p == null || p == "") {
        $("#span_AddressPhone").html("");
        return;
    }


    $.ajax({
        url: "/Handler/IsUserInfoExistHandler.ashx",
        type: "get",
        dataType: "json",
        data: { type: 1, Phone: p, orderId: $orderId, _: Math.random() },
        async: true,
        cache: false,
        complete: function () { },
        success: function (result) {
            if (result.Status) {
                $(".loanProductOrderWorkPhoneList").empty();
                $.each(result.Data, function (index, item) {
                    //获取到所有的重复项目的订单
                    $("#LoanProductOrderWorkPhoneTemplate").tmpl(item).appendTo($(".loanProductOrderWorkPhoneList"));
                });
                $("#ModalLabel_AddressPhone").html("查询的" + p + "电话在以下项目中有过记录");
            } else {
                $("#span_AddressPhone").html("电话信息查询无重复记录!");
                $("#span_AddressPhone").css("color", "green");
                $("#span_AddressPhone").css("font-size", "12px");
            }
        }
    });

}

//工作证明人1
function showUserRepeatCertifyTel(p) {
    if (p == null || p == "") {
        $("#span_CertifyTel").html("");
        return;
    } 
    $.ajax({
        url: "/Handler/IsUserInfoExistHandler.ashx",
        type: "get",
        dataType: "json",
        data: { type: 1, Phone: p, orderId: $orderId, _: Math.random() },
        async: true,
        cache: false,
        complete: function () { },
        success: function (result) {
            if (result.Status) {
                $(".loanProductOrderCertifyTelList").empty();
                $.each(result.Data, function (index, item) {
                    //获取到所有的重复项目的订单
                    $("#LoanProductOrderCertifyTelTemplate").tmpl(item).appendTo($(".loanProductOrderCertifyTelList"));
                });
                $("#ModalLabel_CertifyTel").html("查询的" + p + "电话在以下项目中有过记录");
            } else {
                $("#span_CertifyTel").html("无重复记录!");
                $("#span_CertifyTel").css("color", "green");
                $("#span_CertifyTel").css("font-size", "12px");
            }
        }
    });
}
//工作证明人2
function showUserRepeatCertifyTel2(p) {
    if (p == null || p == "") {
        $("#span_CertifyTel2").html("");
        return;
    }

    $.ajax({
        url: "/Handler/IsUserInfoExistHandler.ashx",
        type: "get",
        dataType: "json",
        data: { type: 1, Phone: p, orderId: $orderId, _: Math.random() },
        async: true,
        cache: false,
        complete: function () { },
        success: function (result) {
            if (result.Status) {
                $(".loanProductOrderCertifyTel2List").empty();
                $.each(result.Data, function (index, item) {
                    //获取到所有的重复项目的订单
                    $("#LoanProductOrderCertifyTel2Template").tmpl(item).appendTo($(".loanProductOrderCertifyTel2List"));
                });
                $("#ModalLabel_CertifyTel2").html("查询的" + p + "电话在以下项目中有过记录");
            } else {
                $("#span_CertifyTel2").html("无重复记录!");
                $("#span_CertifyTel2").css("color", "green");
                $("#span_CertifyTel2").css("font-size", "12px");
            }
        }
    });

}

function showUserRepeatLineaKinPhone(p) {
    if (p == null || p == "") {
        $("#span_LineaKinPhone").html("");
        return;
    }

    $.ajax({
        url: "/Handler/IsUserInfoExistHandler.ashx",
        type: "get",
        dataType: "json",
        data: { type: 1, Phone: p, orderId: $orderId, _: Math.random() },
        async: true,
        cache: false,
        complete: function () { },
        success: function (result) {
            if (result.Status) {
                $(".loanProductOrderLineaKinPhoneList").empty();
                $.each(result.Data, function (index, item) {
                    //获取到所有的重复项目的订单
                    $("#LoanProductOrderLineaKinPhoneTemplate").tmpl(item).appendTo($(".loanProductOrderLineaKinPhoneList"));
                });
                $("#ModalLabel_LineaKinPhone").html("查询的" + p + "电话在以下项目中有过记录");
            } else {
                $("#span_LineaKinPhone").html("无重复记录!");
                $("#span_LineaKinPhone").css("color", "green");
                $("#span_LineaKinPhone").css("font-size", "12px");
            }
        }
    });

}


function showUserRepeatOtherLinkManPhone(p) {
    if (p == null || p == "") {
        $("#span_OtherLinkManPhone").html("");
        return;
    }


    $.ajax({
        url: "/Handler/IsUserInfoExistHandler.ashx",
        type: "get",
        dataType: "json",
        data: { type: 1, Phone: p, orderId: $orderId, _: Math.random() },
        async: true,
        cache: false,
        complete: function () { },
        success: function (result) {
            if (result.Status) {
                $(".loanProductOrderOtherLinkManPhoneList").empty();
                $.each(result.Data, function (index, item) {
                    //获取到所有的重复项目的订单
                    $("#LoanProductOrderOtherLinkManPhoneTemplate").tmpl(item).appendTo($(".loanProductOrderOtherLinkManPhoneList"));
                });
                $("#ModalLabel_OtherLinkManPhone").html("查询的" + p + "电话在以下项目中有过记录");
            } else {
                $("#span_OtherLinkManPhone").html("无重复记录!");
                $("#span_OtherLinkManPhone").css("color", "green");
                $("#span_OtherLinkManPhone").css("font-size", "12px");
            }
        }
    });

}


function showUserRepeatEmergLinkManPhone1(p) {
    if (p == null || p == "") {
        $("#span_EmergLinkManPhone1").html("");
        return;
    }

    $.ajax({
        url: "/Handler/IsUserInfoExistHandler.ashx",
        type: "get",
        dataType: "json",
        data: { type: 1, Phone: p, orderId: $orderId, _: Math.random() },
        async: true,
        cache: false,
        complete: function () { },
        success: function (result) {
            if (result.Status) {
                $(".loanProductOrderEmergLinkManPhone1List").empty();
                $.each(result.Data, function (index, item) {
                    //获取到所有的重复项目的订单
                    $("#LoanProductOrderEmergLinkManPhone1Template").tmpl(item).appendTo($(".loanProductOrderEmergLinkManPhone1List"));
                });
                $("#ModalLabel_EmergLinkManPhone1").html("查询的" + p + "电话在以下项目中有过记录");
            } else {
                $("#span_EmergLinkManPhone1").html("无重复记录!");
                $("#span_EmergLinkManPhone1").css("color", "green");
                $("#span_EmergLinkManPhone1").css("font-size", "12px");
            }
        }
    });

}


function showUserRepeatEmergLinkManPhone2(p) {
    if (p == null || p == "") {
        $("#span_EmergLinkManPhone2").html("");
        return;
    }
    $.ajax({
        url: "/Handler/IsUserInfoExistHandler.ashx",
        type: "get",
        dataType: "json",
        data: { type: 1, Phone: p, orderId: $orderId, _: Math.random() },
        async: true,
        cache: false,
        complete: function () { },
        success: function (result) {
            if (result.Status) {
                $(".loanProductOrderEmergLinkManPhone2List").empty();
                $.each(result.Data, function (index, item) {
                    //获取到所有的重复项目的订单
                    $("#LoanProductOrderEmergLinkManPhone2Template").tmpl(item).appendTo($(".loanProductOrderEmergLinkManPhone2List"));
                });
                $("#ModalLabel_EmergLinkManPhone2").html("查询的" + p + "电话在以下项目中有过记录");
            } else {
                $("#span_EmergLinkManPhone2").html("无重复记录!");
                $("#span_EmergLinkManPhone2").css("color", "green");
                $("#span_EmergLinkManPhone2").css("font-size", "12px");
            }
        }
    });
}

